import { getFirstpage } from "@/utils/api";

//首页
const firstPage = {
  namespaced: true,
  state: () => ({
    mainListL: [],
    mainListR: [],
    _mainListL: [],
    _mainListR: [],
    bannerList: [],
  }),
  actions: {
    //获取首页数据
    async firstPageData({ commit }) {
      let res = await getFirstpage();
      commit("firstPageDatas", res.data);
    },
  },
  mutations: {
    //获得并存储数据2
    firstPageDatas(state, payload) {
      state._mainListL = payload.mainListL;
      state._mainListR = payload.mainListR;
      state.bannerList = payload.bannerList;
    },
    getFirst(state) {
      state.mainListL.push(state._mainListL[0]);
      state.mainListR.push(state._mainListR[0]);
    },
    getMore(state) {
      if (state._mainListL.length > 0) {
        state.mainListL.push(state._mainListL.pop());
      }
      if (state._mainListR.length > 0) {
        state.mainListR.push(state._mainListR.pop());
      }
    },
  },
};

export default firstPage;
